import 'package:flutter/material.dart';
import 'package:flutter_api/modules/common/code_screen.dart';
import 'package:flutter_api/modules/home/home.dart';
import 'package:flutter_api/modules/widget_basic/basic_widget.dart';
import 'package:flutter_api/modules/widget_helper/helper_widget.dart';
import 'package:flutter_api/modules/widget_layout/layout_widget.dart';

//配置全局路由映射
class AppRouter {
  static final String initRoute = HomeScreen.routeName;

  static final routes = {
    HomeScreen.routeName: (context) => HomeScreen(), //根路由
    CodeScreen.routeName: (context) => CodeScreen(),
    BasicWidgetScreen.routeName: (context) => BasicWidgetScreen(),
    HelperWidgetScreen.routeName: (context) => HelperWidgetScreen(),
    LayoutWidgetScreen.routeName: (context) => LayoutWidgetScreen(),
  };

//配置路由传值
  static final RouteFactory onGenerateRoute = (RouteSettings settings) {
    // 统一处理
    final String name = settings.name;
    final Function pageContentBuilder = routes[name];
    if (pageContentBuilder != null) {
      if (settings.arguments != null) {
        final Route route = MaterialPageRoute(
            builder: (context) =>
                pageContentBuilder(context, arguments: settings.arguments));
        return route;
      } else {
        final Route route = MaterialPageRoute(
            builder: (context) => pageContentBuilder(context));
        return route;
      }
    }
    return null;
  };
}
